<!DOCTYPE html>
<html lang="en">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"/>
    <meta name="renderer" content="webkit">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <script type="text/javascript" src="//api.map.baidu.com/api?type=webgl&v=1.0&ak=WlBO6Siag79DGuTsNTjUQtafziYEHaRz"></script>
    <title>根据经纬度定位</title>
    <style>
        html, body, #allmap{
            width: 100%;
            height: 100%;
            padding: 0;
            margin: 0;
            overflow: hidden;
        }
        #result{
            padding: 7px 10px;
            position: fixed;
            top: 10px;
            left: 20px;
            width: 450px;
            background: #fff;
            box-shadow: 0 2px 6px 0 rgba(27, 142, 236, 0.5);
            border-radius: 7px;
            z-index: 99;
        }
        #result input{
            width:130px;
            margin-right:10px;
            height:25px;
            border: 1px solid rgba(27, 142, 236, 0.5);
            border-radius: 5px;
        }
        #result button{
            border: 1px solid rgba(27, 142, 236, 0.5);
            border-radius: 5px;
            background: rgba(27, 142, 236, 0.5);
            color: #fff
        }
    </style>
    <link rel="stylesheet" href="/css/pintuer.css">
    <link rel="stylesheet" href="/css/admin.css">
    <script src="/js/jquery.js"></script>
    <script src="/js/pintuer.js"></script>
    <script src="/js/vuejs-2.5.16.js"></script>
    <script src="/js/axios-0.18.0.js"></script>
    <!-- 引入样式 -->
    <link rel="stylesheet" href="/element-ui/lib/theme-chalk/index.css">
    <!-- 引入组件库 -->
    <script src="/element-ui/lib/index.js"></script>
</head>
<body>
<div id='allmap'></div>
<div id='result'>
    经度: <input id="lng" type="text" v-model="jingdu" />
    纬度: <input id="lat" type="text" v-model="weidu" />
    <button onclick="theLocation()"/>查询</button>

    <table class="table table-hover ">
        <tr>
            <th width="10%"></th>
            <th width="15%"></th>
        </tr>

        <tr>
            <td><img :src="avatar "  width="120" height="120"/></td>
            <td>
                <table class="table table-hover ">
                    <tr>
                        <td><div width="20"><font size="3"><b>昵称：</b><font/></div></td>
                        <td><div ><font size="3"><b>{{nickname}}</b><font/></div></td>
                    </tr>
                    <tr>
                        <td><div width="20"><font size="3"><b>性别：</b><font/></div></td>
                        <td><div ><font size="3"><b>{{gender}}</b><font/></div></td>
                    </tr>
                    <tr>
                        <td><div width="20"><font size="3"><b>城市：</b><font/></div></td>
                        <td><div ><font size="3"><b>{{city}}</b><font/></div></td>
                    </tr>
                    <tr>
                        <td><div width="20"><font size="3"><b>地址：</b><font/></div></td>
                        <td><div ><font size="3"><b>{{address}}</b><font/></div></td>
                    </tr>
                </table>
            </td>
        </tr>
    </table>
</div>
<script>
    // 百度地图API功能
    var map = new BMapGL.Map("allmap");
    map.centerAndZoom(new BMapGL.Point(116.331398,39.897445),11);
    map.enableScrollWheelZoom(true);

    // 用经纬度设置地图中心点
    function theLocation(){
        if(document.getElementById("lng").value != "" && document.getElementById("lat").value != ""){
            map.clearOverlays();
            var new_point = new BMapGL.Point(document.getElementById("lng").value,document.getElementById("lat").value);
            var marker = new BMapGL.Marker(new_point);  // 创建标注
            map.addOverlay(marker);              // 将标注添加到地图中
            map.panTo(new_point);
        }
    }
</script>
<script>
    const app = new Vue({
        el:'#result' ,
        data:{
            nickname:'',
            gender:'',
            address:'',
            city:'',
            avatar:'',
            jingdu:'',
            weidu:''
        },
        methods:{
            findById(id){
                axios.get("/baidumap/findById?id="+id).then(resp=>{
                    console.log(resp.data);
                this.nickname = resp.data.nickname;
                this.gender = resp.data.gender;
                this.city = resp.data.city;
                this.address = resp.data.address;
                this.avatar = resp.data.avatar;
                this.jingdu = resp.data.longitude;
                this.weidu = resp.data.latitude;


            });
            }
        },
        created(){
            //获取地址栏上id值,若有值的话,就需要发送ajax请求查询影视信息
            //location.search :获取参数内容 ?id=4
            let id = location.search.split("=")[1];
            if(id){
                this.findById(id);
            }

        }
    });
</script>
</body>
</html>